package com.zgkxzx.数据结构;

import com.zgkxzx.java.bean.Person;
import com.zgkxzx.数据结构.哈希表.HashLinkedTable;
import com.zgkxzx.数据结构.堆.Heap;
import com.zgkxzx.数据结构.数组.AutoIncreaseArray;
import com.zgkxzx.数据结构.栈.ArrayStack;
import com.zgkxzx.数据结构.栈.BaseStack;
import com.zgkxzx.数据结构.树.二叉树.BinaryTree;
import com.zgkxzx.数据结构.树.二叉树.BinaryTree2;
import com.zgkxzx.数据结构.树.二叉树.StudentNode;
import com.zgkxzx.算法.算数表达式解析.Mid2After;

/**
 * 创建者   zgkxzx
 * 创建日期 2018/5/12.
 * 功能描述
 */
public class DataStructTest {
    public static void test(){
        BaseStack<Person> personArrayStack = new ArrayStack<>(20);
        personArrayStack.push(new Person("ad124zx"));
        personArrayStack.push(new Person("d123zx"));
        personArrayStack.push(new Person("w122zx"));
        personArrayStack.push(new Person("3125zx"));

        Person person1 ;
        while((person1 = personArrayStack.pop())!=null){
            System.out.println(person1);
        }

        //算术表达式算法测试
        Mid2After mid2After = new Mid2After();
        mid2After.runTest("3+4-5");


        //hash

        HashLinkedTable<String> stringHashArrayTable = new HashLinkedTable<>(10);

        stringHashArrayTable.put(1,"zgkxzx");
        stringHashArrayTable.put(2,"zhangsan");
        stringHashArrayTable.put(3,"lisi");
        stringHashArrayTable.put(11,"wangwu");

        stringHashArrayTable.print();

        String string1 = stringHashArrayTable.get(1);
        System.out.println(" string 1 "+string1);

        String string2 = stringHashArrayTable.get(2);
        System.out.println(" string 2 "+string2);

        String string11 = stringHashArrayTable.get(11);
        System.out.println(" string 11 "+string11);


        BinaryTree2 binaryTree2 = new BinaryTree2();
        binaryTree2.insertNode(50);

        binaryTree2.insertNode(34);

        binaryTree2.insertNode(56);

        binaryTree2.insertNode(54);

        binaryTree2.insertNode(60);
        System.out.println("-----------------");
        binaryTree2.print();
        binaryTree2.delete(56);
        System.out.println("-----------------");
        binaryTree2.print();
        System.out.println("-----------------");
        binaryTree2.prePrint();

        ////////////////////////////////////////////
        AutoIncreaseArray<String> strArray = new AutoIncreaseArray<>(3);
        strArray.add("zgkxz");
        strArray.add("zgkxz1");
        strArray.add("zgkxz2");
        strArray.add("zgkxz3");
        strArray.add("zgkxz42");
        strArray.add("zgkxz2q");
        strArray.add("zgkxz3w");
        strArray.add("zgkxz4e2");
        strArray.add("zgkxz5");
        strArray.add("zgkxz6");
        strArray.print();

        //////////////////////////////////////
        Heap heap = new Heap();
        heap.insert(70);
        heap.insert(40);
        heap.insert(50);
        heap.insert(20);
        heap.insert(60);
        heap.insert(100);
        heap.insert(80);
        heap.insert(30);
        heap.insert(10);

        heap.display();
    }


    //二叉树
    private static void binaryTreeTest() {
        BinaryTree.Node<StudentNode> root = new BinaryTree.Node(new StudentNode(21, "zgkxzx", "014012223"));
        //root.data = new StudentNode(21,"zgkxzx","014012223");
        BinaryTree<StudentNode> binaryTree = new BinaryTree<>(root);
        //binaryTree.root.leftNode = new BinaryTree.Node<>(new StudentNode(23, "ddad", "dfadsf"));
        //binaryTree.root.rightNode = new BinaryTree.Node<>(new StudentNode(20, "aad2ddd", "dfa222dsf"));
        binaryTree.insertNode(new BinaryTree.Node<>(new StudentNode(20, "aad2ddd", "dfa222dsf")));
        binaryTree.insertNode(new BinaryTree.Node<>(new StudentNode(12, "xiaoxiao", "xfa222dsf")));
        binaryTree.insertNode(new BinaryTree.Node<>(new StudentNode(27, "zhao", "dfads22f")));
        binaryTree.insertNode(new BinaryTree.Node<>(new StudentNode(43, "ddad", "dfadsf")));
        binaryTree.insertNode(new BinaryTree.Node<>(new StudentNode(25, "xiado", "xfa222dsf")));


        BinaryTree.inOrderTraverse(root);


        int degree = BinaryTree.getTreeDeep(root);

        System.out.println("树的度 ：" + degree);

        BinaryTree.Node<StudentNode> maxNode = BinaryTree.getMaxValue(root);
        BinaryTree.inOrderTraverse(root);
        System.out.println("最大值节点 ：" + maxNode.data);

        BinaryTree.Node<StudentNode> maxNode1 = BinaryTree.getMaxValue2(root);

        System.out.println("最大值节点1 ：" + maxNode1.data);

        int leafCount = BinaryTree.getLeafCount(root, 0);

        System.out.println("leafCount ：" + leafCount);

        BinaryTree.Node<StudentNode> studentNodeNode = BinaryTree.searchNode(root, new BinaryTree.Node<>(new StudentNode(0, "zgkxzx", "xfa222dsf")));

        System.out.println("搜索到的节点 ：" + studentNodeNode.data);


    }
}
